﻿//
// Created by work on 24-6-6.
//

#ifndef IOT_PLAT_CRTMODELYKINFO_H
#define IOT_PLAT_CRTMODELYKINFO_H

#include "CRtModelSigBase.h"

class CRtModelYkInfo : public CRtModelSigBase{
    Q_OBJECT
public:

    bool en_write;

    struct SYkValue {
        int value = 0;
        QString v_descr = "test";
        QJsonObject v_image = QJsonObject();
        QJsonObject toJson()const {
            QJsonObject obj;
            obj["value"] = value;
            obj["v_descr"] = v_descr;
            obj["v_image"] = v_image;
            return obj;
        }

        void fromJson(QJsonObject obj) {
            value = obj["value"].toInt();
            v_descr = obj["v_descr"].toString();
            v_image = obj["v_image"].toObject();
        }
    };

    enum EModelYkCol{
        EEn_write = 7,
        EValues
    };
    std::vector<SYkValue> values;
    static std::map<CRtModelYkInfo::EModelYkCol, QString> rtModelYkColToStringMap;
    static std::map<CRtModelYkInfo::EModelYkCol, QString> ykColFieldsNameMap;
    static std::map<CRtModelYkInfo::EModelYkCol, CValue::EValueType> rtYkDataTypeByField;

public:
    explicit CRtModelYkInfo(QObject *parent = nullptr);

    QJsonArray valuesToJson()const;
    void valuesFromJson(QJsonArray json);

    virtual QString getFieldNameByCol(int col)override;

    virtual QVariant getFieldValueByFielddName(const QString& name)override;

    virtual void setFieldValueByCol(int col, const QVariant& value)override;

    virtual QJsonObject toJson()override;

    virtual void fromJson(const QJsonObject &json)override;

    virtual QSharedPointer<IModel> createEmpty()override;

    virtual bool sync(bool dir = true) override;
};

#define YK_ENUM CRtModelYkInfo::EModelYkCol
#define ykFieldName(type)           CRtModelYkInfo::rtModelYkColToStringMap.find(type)->second
#define ykColFieldName(type)        CRtModelYkInfo::ykColFieldsNameMap.find(type)->second
#define ykDataTypeByField(type)     CRtModelYkInfo::rtYkDataTypeByField.find(type)->second
#define YK_COL_SIZE                 (SIGBASE_COL_SIZE + rtModelYkColToStringMap.size())


#endif //IOT_PLAT_CRTMODELYKINFO_H
